# 3.3 PIR Motion Sensor ## 3.3.1 Overview The PIR motion sensor adopts RE200B-P element. Based on pyroelectric effect, the sensor is able to detect the infrared ray emitted by human body or animal. With Fresnel lens, it can even detect farther and wider. When a nearby human or animal motion is detected, the sensor outputs a high level. ## 3.3.2 Schematic Diagram ![6-3](./media/6-3-2.png) **Working principle:** The human body maintains at 37 degrees, so it will emit a specific wavelength of about 10μm infrared. The sensor captures 10μM infrared to determine whether there is a motion. ## 3.3.3 Code Blocks 1. ![j15](./media/j15.png) This block reads PIR motion sensor value. If there is a human motion, it outputs 1; otherwise, it outputs 0. 2. ![j16](./media/j16.png) This block determines whether a condition is satisfied. If yes, code in “if” will be executed. Or else, code in “else” will be executed. ## 3.3.4 Test Code ## 3.3.4.1 Build Code There are two ways to upload the code: directly open the code file we provide; or manually build blocks. **Directly open the code file we provide:** 1. Click ![](./media/j68.png) and choose `Load from your computer` ![](./media/j67.png) 2. We have already downloaded the codes on computer desktop, so open the file and choose `3-3-pir.sb3` **Manually build blocks:** 1. In ![events](./media/events.png), find ![j1](./media/j1.png) block. 2. In ![serial](./media/serial.png), find ![j12](./media/j12.png) block and set baud rate to 9600, and put it under ![j1](./media/j1.png). 3. In ![control](./media/control.png), drag ![j2](./media/j2.png). ![6-4-4-1-1](./media/6-3-4-1-1.png) ![6-4-4-1-2](./media/6-3-4-1-2.png) 4. In ![control](./media/control.png), drag ![j16](./media/j16.png) into ![j2](./media/j2.png). ![6-3](./media/6-3-4-1-1.png) 5. In ![pir](./media/pir.png), find and put ![j15](./media/j15.png) into the condition box of ![j16](./media/j16.png). Add the following block under "if": ![6-3](./media/6-3-4-1-2.png) prints “Someone!”; Add the following block under "else": ![6-3](./media/6-3-4-1-3.png) prints “No one!” **Complete Test Code** ![6-3](./media/6-3-4-1-4.png) ## 3.3.4.2 Test Result After uploading code, when human motion is detected, the monitor prints “Someone!”; If not, it shows “No one!” (Note that click ![6-2](./media/6-2-4-1-4.png) to set the baud rate before uploading code to avoid garbled words.) ![6-3](./media/6-3-4-2.png)